import {ajax} from "@/utils/ajax.js"

export const getById=(id)=>{
	return ajax({
		url:'/dynamicInfo/getByIdInfo',
		method:'GET',
		data:{
			id
		}
	})
}

export const remove = async (id) => {
	if (remove.lock) {
		throw new Error('正在请求中')
	}
	try {
		remove.lock = true;
		const res = await ajax({
			url: '/dynamicInfo/delete',
			data: {
				id
			}
		})
		return res;
	} catch (e) {
		throw e
	} finally {
		remove.lock = false;
	}
}


export const add = async ({
	petId,
	content,
	addr,
	longitude,
	latitude,
	images,
	videos,
	topic,
	circleId,
	moduleId
}) => {
	if (add.lock) {
		throw new Error('正在请求中')
	}
	try {
		add.lock = true;
		const res = await ajax({
			url: '/dynamicInfo/add',
			data: {
				petId,
				content,
				addr,
				longitude,
				latitude,
				images,
				videos,
				topic,
				circleId,
				moduleId
			}
		})
		return res;
	} catch (e) {
		throw e
	} finally {
		add.lock = false;
	}
}

export const getFriendMoments = ({pageNo=1,pageSize=10})=>{
	return ajax({
		url: '/dynamicInfo/getFriendDynamic',
		data: {
			pageNo,
			pageSize
		}
	})
}

export const getFriendMomentsByUser = ({id,pageNo=1,pageSize=10})=>{
	return ajax({
		url: '/dynamicInfo/getByUserIdFriendDynamic',
		data: {
			friendId:id,
			pageNo,
			pageSize
		}
	})
}